import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2024-04-14
 * Time: 8:55
 */
class MyThreadPool{
    BlockingQueue<Runnable> blockingQueue=new ArrayBlockingQueue<>(1000);
    public MyThreadPool(int capacity){
        for (int i = 0; i <capacity ; i++) {
            Thread t=new Thread(()->{
                try{
                    Runnable runnable=blockingQueue.take();
                    runnable.run();
                }catch (InterruptedException e){
                    e.printStackTrace();
                }

            });
            t.start();
        }
    }
    public void submit(Runnable runnable) throws InterruptedException {
        blockingQueue.put(runnable);
    }
}
public class Demo2 {
    public static void main(String[] args) throws InterruptedException {
        MyThreadPool myThreadPool=new MyThreadPool(100);
        for (int i = 0; i < 10000; i++) {
            int id=i;
         myThreadPool.submit(new Runnable() {
             @Override
             public void run() {
                 System.out.println("hello "+id+","+Thread.currentThread().getName());
             }
         });
        }
    }
}
